import { request } from '@/service'

/**
 * 用户的网络请求
 */
export const postUserListData = (formData: any = {}) => {
  return request.post({
    url: '/users/list',
    data: {
      name: formData.name,
      realname: formData.realName,
      cellphone: formData.cellphone,
      enable: formData.enable,
      pagenum: formData.pageNum,
      pagesize: formData.pageSize
    }
  })
}

export function deleteUserApi(id: number) {
  return request.delete({
    url: `/user/${id}`
  })
}

/**
 * 创建用户
 * @param userInfo
 */
export function createUserDataApi(userInfo: any) {
  return request.post({
    url: `/user`,
    data: {
      name: userInfo.name,
      intro: userInfo.realname,
      department: userInfo.departmentId,
      cellphone: userInfo.cellphone,
      roleId: userInfo.roleId,
      password: userInfo.password
    }
  })
}

export function editUserData(id: number, userInfo: any) {
  return request.patch({
    url: `/user/${id}`,
    data: userInfo
  })
}

// 针对不同页面的网络请求
export function postPageListData(pageName: string, queryInfo: any) {
  return request.post({
    url: `${pageName}/list`,
    data: queryInfo
  })
}

export function delById(pageName: string, id: number) {
  return request.delete({
    url: `/${pageName}/${id}`
  })
}

export function createDataApi(pageName: string, pageInfo: any) {
  return request.post({
    url: `/${pageName}`,
    data: pageInfo
  })
}

export function editDataApi(pageName: string, id: number, pageInfo: any) {
  return request.post({
    url: `/${pageName}/${id}`,
    data: pageInfo
  })
}
